org 0x07c00
jmp short begin_boot

bootmesg db "Our OS boot sector loading......"
pm_mesg db "Switching to protected mode....."

dw 512
db 1
dw 1
db 2
dw 0x000e0
dw 0x0b40
db 0x0f0
dw 9
dw 18
dw 2
dw 0

print_mesg:
	mov ah, 0x13
	mov al, 0x00
	mov bx, 0x0007
	mov cx, 0x20
	mov dx, 0x0000
	int 0x10
	ret

get_key:
	mov ah, 0x00
	int 0x16
	ret

clrscr:
	mov ax, 0x0600
	mov cx, 0x0000
	mov dx, 0x174f
	mov bh, 0
	int 0x10
	ret

begin_boot:
	call clrscr
	mov bp, bootmesg
	call print_mesg
	call get_key
bits 16
	call clrscr
	mov ax, 0xb800
	mov gs, ax
	mov word [gs:0], 0x643
	call get_key

	mov ah, 6
	mov word [gs:0], ax
	mov bp, pm_mesg
	call print_mesg

	call get_key
	call clrscr

;	mov ah, 0x00
;	int 0x16
;	mov word [gs:0], 0x647

	cli
	lgdt[gdtr]
	mov eax, cr0
	or al, 0x01
	mov cr0, eax
	jmp codesel:go_pm

bits 32
go_pm:
	mov ax, datasel
	mov ds, ax
	mov es, ax
	mov ax, videosel
	mov gs, ax
	mov word [gs:0], 0x742
	xor ax, ax
	
spin: 
	jmp spin

bits 16
gdtr:
	dw gdt_end-gdt-1
	dd gdt
gdt
nullsel equ $-gdt
gdt0
	dd 0
	dd 0
codesel equ $-gdt
code_gdt
	dw 0x0ffff
	dw 0x0000
	db 0x00
	db 0x09a
	db 0x0cf

	db 0x00
datasel equ $-gdt
data_gdt
	dw 0x0ffff
	dw 0x0000
	db 0x00
	db 0x092
	db 0x0cf
	db 0x00
videosel equ $-gdt
	dw 3999
	dw 0x8000
	db 0x0b
	db 0x92
	db 0x00
	db 0x00
gdt_end

times 510-($-$$) db 0
	dw 0x0aa55
